<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
class FgcmsTemplate {
    
    var $db;
    var $smarty;
    
    function FgcmsTemplate($db, $smarty) {
      	$this->db = $db;
		$this->smarty = $smarty;
    }
    
    function process(){
		  if(isset($_POST['template']) && $_POST['template'] != "") {
			 FgcmsTemplateBean::select_template($this->db, $_POST['template']);
			 $directory = "view_c";
			 $this->delete_directory($directory);
			 ob_clean();
			 header("Location: ./");
		  }
		$alltemplate = FgcmsTemplateBean::get_all_template($this->db);
		$this->smarty->assign("ALLTEMPLATE", $alltemplate);
		
		$activetemplate = FgcmsTemplateBean::get_active_template($this->db);
		$this->smarty->assign("ACTIVETEMPLATE", $activetemplate);
		
		//$this->smarty->display('template.tpl');
	}
	
	function delete_directory($dirname) {
		 if (is_dir($dirname))
			$dir_handle = opendir($dirname);
		 if (!$dir_handle)
			 return false;
		 while($file = readdir($dir_handle)) {
			if ($file != "." && $file != "..") {
			   if (!is_dir($dirname."/".$file))
					unlink($dirname."/".$file);
			}
		}
		 closedir($dir_handle);
		//rmdir($dirname);
		return true;
	} 
}
?>